<template>
  <UserLayout :active-index="'3'" :active-menu="'agent-rental'">
    <div class="agent-rental-content">
      <!-- 未通过中介申请的提示 -->
      <div v-if="!hasAgentAccess" class="no-access-container">
        <div class="no-access-card">
          <div class="no-access-icon">
            <el-icon><User /></el-icon>
          </div>
          <h2>您暂未通过中介申请</h2>
          <p>要使用中介租房管理功能，您需要先通过中介申请审核</p>
          <div class="no-access-actions">
            <el-button type="primary" @click="goToAgentApply">
              <el-icon><Plus /></el-icon>
              申请中介
            </el-button>
            <el-button @click="goToAgentStatus">
              <el-icon><View /></el-icon>
              查看申请状态
            </el-button>
          </div>
          <div class="no-access-tips">
            <h3>申请流程：</h3>
            <ol>
              <li>完成实名认证</li>
              <li>填写中介申请信息</li>
              <li>等待管理员审核</li>
              <li>审核通过后即可使用中介功能</li>
            </ol>
          </div>
        </div>
      </div>

      <!-- 已通过中介申请的内容 -->
      <div v-else>
        <div class="rental-header">
          <h2>中介租房管理</h2>
          <p>管理您代理的房源和租客信息</p>
        </div>

          <!-- 房源统计数据 -->
          <div class="rental-stats">
            <el-row :gutter="20">
              <el-col :span="6">
                <div class="stat-card">
                  <div class="stat-icon bg-blue">
                    <House />
                  </div>
                  <div class="stat-content">
                    <div class="stat-value">{{ totalHouses }}</div>
                    <div class="stat-title">代理房源</div>
                  </div>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="stat-card">
                  <div class="stat-icon bg-green">
                    <OfficeBuilding />
                  </div>
                  <div class="stat-content">
                    <div class="stat-value">{{ promotingHouses }}</div>
                    <div class="stat-title">推广中</div>
                  </div>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="stat-card">
                  <div class="stat-icon bg-orange">
                    <Check />
                  </div>
                  <div class="stat-content">
                    <div class="stat-value">{{ completedHouses }}</div>
                    <div class="stat-title">已完成</div>
                  </div>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="stat-card">
                  <div class="stat-icon bg-red">
                    <User />
                  </div>
                  <div class="stat-content">
                    <div class="stat-value">{{ tenantsCount }}</div>
                    <div class="stat-title">租客数</div>
                  </div>
                </div>
              </el-col>
            </el-row>
          </div>

          <!-- 快捷操作 -->
          <div class="quick-actions">
            <el-row :gutter="20">
              <el-col :span="8">
                <div class="action-card" @click="goToAppointments">
                  <div class="action-icon">
                    <el-icon><Calendar /></el-icon>
                  </div>
                  <div class="action-content">
                    <div class="action-title">预约申请管理</div>
                    <div class="action-desc">处理代理房源的看房预约申请</div>
                  </div>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="action-card" @click="goToReports">
                  <div class="action-icon">
                    <el-icon><DataAnalysis /></el-icon>
                  </div>
                  <div class="action-content">
                    <div class="action-title">业绩统计</div>
                    <div class="action-desc">查看代理业绩和收益统计</div>
                  </div>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="action-card" @click="goToReports">
                  <div class="action-icon">
                    <el-icon><DataAnalysis /></el-icon>
                  </div>
                  <div class="action-content">
                    <div class="action-title">业绩报告</div>
                    <div class="action-desc">查看代理业绩和统计数据</div>
                  </div>
                </div>
              </el-col>
            </el-row>
          </div>

          <!-- 房源列表 -->
          <div class="rental-list">
            <el-tabs v-model="activeTab" @tab-change="handleTabChange">
              <el-tab-pane label="所有代理" name="all">
                <div class="rental-container">
                  <!-- 空状态显示 -->
                  <el-empty v-if="allHouses.length === 0 && !loading" description="暂无代理房源">
                    <el-button type="primary" @click="goToApply">申请代理房源</el-button>
                  </el-empty>
                  <!-- 加载状态 -->
                  <div v-else-if="loading" class="loading-container">
                    <el-skeleton :rows="3" animated />
                  </div>
                  <!-- 房源列表 -->
                  <el-row :gutter="20" v-else>
                    <el-col
                        :span="8"
                        v-for="house in allHouses"
                        :key="house.id"
                        class="house-col"
                    >
                      <div class="house-card" @click="viewHouseDetail(house.id)">
                        <div class="house-image">
                          <img :src="house.image" :alt="house.title" />
                          <div class="house-price">¥{{ house.price }}/月</div>
                          <div class="house-status" :class="house.statusClass">
                            {{ house.status }}
                          </div>
                        </div>
                        <div class="house-info">
                          <h3 class="house-title">{{ house.title }}</h3>
                          <p class="house-address">
                            <el-icon><Location /></el-icon>
                            {{ house.address }}
                          </p>
                          <div class="house-meta">
                            <span>{{ house.layout }}</span>
                            <span>{{ house.area }}㎡</span>
                            <span>{{ house.orientation }}</span>
                          </div>
                          <div class="house-tags">
                            <el-tag
                                v-for="tag in house.tags"
                                :key="tag"
                                size="small"
                                :type="getTagType(tag)"
                            >
                              {{ tag }}
                            </el-tag>
                          </div>
                          <div class="house-actions">
                            <el-button
                                size="small"
                                :type="getActionType(house.status)"
                                @click.stop="handleHouseAction(house)"
                            >
                              {{ getActionText(house.status) }}
                            </el-button>
                            <el-button
                                size="small"
                                @click.stop="viewHouseDetail(house.id)"
                            >
                              查看详情
                            </el-button>
                          </div>
                        </div>
                      </div>
                    </el-col>
                  </el-row>
                </div>
              </el-tab-pane>
              <el-tab-pane label="推广中" name="promoting">
                <div class="rental-container">
                  <!-- 空状态显示 -->
                  <el-empty v-if="promotingHousesList.length === 0 && !loading" description="暂无推广中的房源">
                    <el-button type="primary" @click="goToApply">申请代理房源</el-button>
                  </el-empty>
                  <!-- 房源列表 -->
                  <el-row :gutter="20" v-else>
                    <el-col
                        :span="8"
                        v-for="house in promotingHousesList"
                        :key="house.id"
                        class="house-col"
                    >
                      <div class="house-card" @click="viewHouseDetail(house.id)">
                        <div class="house-image">
                          <img :src="house.image" :alt="house.title" />
                          <div class="house-price">¥{{ house.price }}/月</div>
                          <div class="house-status promoting">
                            推广中
                          </div>
                        </div>
                        <div class="house-info">
                          <h3 class="house-title">{{ house.title }}</h3>
                          <p class="house-address">
                            <el-icon><Location /></el-icon>
                            {{ house.address }}
                          </p>
                          <div class="house-meta">
                            <span>{{ house.layout }}</span>
                            <span>{{ house.area }}㎡</span>
                            <span>{{ house.orientation }}</span>
                          </div>
                          <div class="house-tags">
                            <el-tag
                                v-for="tag in house.tags"
                                :key="tag"
                                size="small"
                                :type="getTagType(tag)"
                            >
                              {{ tag }}
                            </el-tag>
                          </div>
                          <div class="house-actions">
                            <el-button
                                size="small"
                                type="warning"
                                @click.stop="stopPromotion(house)"
                            >
                              停止推广
                            </el-button>
                            <el-button
                                size="small"
                                @click.stop="viewHouseDetail(house.id)"
                            >
                              查看详情
                            </el-button>
                          </div>
                        </div>
                      </div>
                    </el-col>
                  </el-row>
                </div>
              </el-tab-pane>
              <el-tab-pane label="已完成" name="completed">
                <div class="rental-container">
                  <el-row :gutter="20">
                    <el-col
                        :span="8"
                        v-for="house in completedHousesList"
                        :key="house.id"
                        class="house-col"
                    >
                      <div class="house-card" @click="viewHouseDetail(house.id)">
                        <div class="house-image">
                          <img :src="house.image" :alt="house.title" />
                          <div class="house-price">¥{{ house.price }}/月</div>
                          <div class="house-status completed">
                            已完成
                          </div>
                        </div>
                        <div class="house-info">
                          <h3 class="house-title">{{ house.title }}</h3>
                          <p class="house-address">
                            <el-icon><Location /></el-icon>
                            {{ house.address }}
                          </p>
                          <div class="house-meta">
                            <span>{{ house.layout }}</span>
                            <span>{{ house.area }}㎡</span>
                            <span>{{ house.orientation }}</span>
                          </div>
                          <div class="house-tags">
                            <el-tag
                                v-for="tag in house.tags"
                                :key="tag"
                                size="small"
                                :type="getTagType(tag)"
                            >
                              {{ tag }}
                            </el-tag>
                          </div>
                          <div class="house-actions">
                            <el-button
                                size="small"
                                @click.stop="viewHouseDetail(house.id)"
                            >
                              查看详情
                            </el-button>
                          </div>
                        </div>
                      </div>
                    </el-col>
                  </el-row>
                </div>
              </el-tab-pane>
            </el-tabs>
          </div>

          <!-- 分页 -->
          <div class="pagination-container">
            <el-pagination
                v-model:current-page="currentPage"
                v-model:page-size="pageSize"
                :page-sizes="[9, 18, 36, 72]"
                :total="totalHouses"
                layout="total, sizes, prev, pager, next, jumper"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
            />
          </div>
        </div>
      </div>
  </UserLayout>

  <!-- 取消申请进度弹窗 -->
  <el-dialog
      v-model="cancelProgressVisible"
      title="取消代理申请进度"
      width="500px"
      :before-close="() => cancelProgressVisible = false"
  >
    <div v-if="currentCancelRequest" class="cancel-progress">
      <el-descriptions :column="1" border>
        <el-descriptions-item label="申请编号">
          {{ currentCancelRequest.id }}
        </el-descriptions-item>
        <el-descriptions-item label="申请时间">
          {{ currentCancelRequest.applyTime }}
        </el-descriptions-item>
        <el-descriptions-item label="申请原因">
          {{ currentCancelRequest.reason }}
        </el-descriptions-item>
        <el-descriptions-item label="审核状态">
          <el-tag :type="getProgressType(currentCancelRequest.status)">
            {{ getProgressStatus(currentCancelRequest.status) }}
          </el-tag>
        </el-descriptions-item>
      </el-descriptions>

      <div class="progress-timeline" style="margin-top: 20px;">
        <el-steps :active="currentCancelRequest.status === 'pending' ? 1 : 2" finish-status="success">
          <el-step title="提交申请" description="已提交取消代理申请"></el-step>
          <el-step
              :title="currentCancelRequest.status === 'approved' ? '房东同意' : currentCancelRequest.status === 'rejected' ? '房东拒绝' : '等待房东审核'"
              :description="currentCancelRequest.status === 'pending' ? '房东正在审核中...' : currentCancelRequest.status === 'approved' ? '房东已同意取消代理' : '房东已拒绝申请'"
          ></el-step>
        </el-steps>
      </div>

      <div v-if="currentCancelRequest.status === 'rejected'" class="reject-info" style="margin-top: 15px;">
        <el-alert
            title="申请被拒绝"
            type="error"
            description="房东已拒绝您的取消代理申请，您可以继续推广该房源或重新提交申请。"
            show-icon
            :closable="false"
        />
      </div>

      <div v-if="currentCancelRequest.status === 'approved'" class="approve-info" style="margin-top: 15px;">
        <el-alert
            title="申请已通过"
            type="success"
            description="房东已同意取消代理，该房源将停止推广。"
            show-icon
            :closable="false"
        />
      </div>
    </div>

    <template #footer>
      <el-button @click="cancelProgressVisible = false">关闭</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import UserLayout from '@/components/layout/UserLayout.vue'
import {
  House,
  Check,
  Location,
  Calendar,
  Document,
  DataAnalysis,
  OfficeBuilding,
  User,
  Plus,
  View
} from '@element-plus/icons-vue'
import api from '@/utils/api'
import { getToken, getUserInfo, canAccessAgentFeatures } from '@/utils/auth'

const router = useRouter()
const activeMenu = ref('agent-rental')
const activeIndex = ref('1')
const activeTab = ref('all')
const currentPage = ref(1)
const pageSize = ref(9)

// 中介申请状态
const hasAgentAccess = ref(false)
const loading = ref(true)

// 检查中介申请状态
const checkAgentStatus = async () => {
  try {
    loading.value = true

    // 首先检查用户是否已实名认证
    const userInfo = getUserInfo()
    if (!userInfo || !userInfo.isIdentityVerified) {
      hasAgentAccess.value = false
      return
    }

    // 检查中介申请状态
    const response = await api.get('/agent/auth/result', {
      headers: {
        'info': getToken()
      }
    })

    if (response.data && response.data.code === '200' && response.data.data) {
      const data = response.data.data
      // 只有审核通过(verifyStatus === 2)才能使用中介功能
      hasAgentAccess.value = data.verifyStatus === 2
      console.log('AgentRentalView - 中介申请状态:', data.verifyStatus, '有权限:', hasAgentAccess.value)
    } else {
      // 没有申请记录
      hasAgentAccess.value = false
      console.log('AgentRentalView - 没有申请记录或响应异常')
    }
  } catch (error) {
    console.error('检查中介申请状态失败:', error)
    hasAgentAccess.value = false
  } finally {
    loading.value = false
  }
}

// 跳转到中介申请页面
const goToAgentApply = () => {
  router.push('/agent/apply')
}

// 跳转到申请状态页面
const goToAgentStatus = () => {
  router.push('/agent/status')
}

// 房源统计数据
const totalHouses = ref(0)
const promotingHouses = ref(0)
const completedHouses = ref(0)
const tenantsCount = ref(0)

// 所有代理房源数据
const allHousesData = ref([])


// 根据标签获取标签类型
const getTagType = (tag) => {
  const tagTypes = {
    '近地铁': 'success',
    '精装修': 'warning',
    '拎包入住': 'info',
    '新上架': 'danger',
    '学区房': 'primary',
    '地铁房': 'success',
    '别墅': 'primary',
    '带花园': 'success',
    '独栋': 'warning',
    'loft': 'info',
    '创意空间': 'danger',
    '复式': 'primary',
    '江景房': 'success',
    '近商圈': 'warning',
    '单间': 'info',
    '经济实惠': 'danger',
    '学生首选': 'primary',
    '服务式公寓': 'success',
    '高端': 'warning',
    '配套设施齐全': 'info',
    '市中心': 'danger',
    '交通便利': 'primary',
    '精装': 'success',
    '优质教育资源': 'warning',
    '安静': 'info'
  }
  return tagTypes[tag] || 'info'
}

// 获取操作按钮类型
const getActionType = (status) => {
  switch (status) {
    case '推广中':
      return 'warning'
    case '已完成':
      return 'info'
    default:
      return 'primary'
  }
}

// 获取操作按钮文本
const getActionText = (status) => {
  switch (status) {
    case '推广中':
      return '停止推广'
    case '申请取消中':
      return '申请进度'
    case '已完成':
      return '已完成'
    default:
      return '管理房源'
  }
}

// 顶部导航栏跳转
const goToHome = () => {
  router.push('/')
}

const goToSearch = () => {
  router.push('/house/search')
}

const goToPublish = () => {
  router.push('/house/publish')
}

const goToMessages = () => {
  router.push('/message')
}

// 用户命令处理
const handleUserCommand = (command) => {
  switch (command) {
    case 'profile':
      router.push('/profile')
      break
    case 'settings':
      router.push('/settings')
      break
    case 'logout':
      ElMessage.success('退出登录成功')
      localStorage.removeItem('userEmail')
      localStorage.removeItem('isLoggedIn')
      router.push('/login')
      break
  }
}

// 侧边栏跳转
const goToPublishNew = () => {
  router.push('/house/publish')
}

const goToMyHouses = () => {
  router.push('/house/my-houses')
}



const goToAgentHouses = () => {
  router.push('/agent/houses')
}

const goToTenant = () => {
  router.push('/rental/tenant')
}

const goToLandlord = () => {
  router.push('/rental/landlord')
}

const goToAgentRental = () => {
  router.push('/rental/agent')
}

const goToProfile = () => {
  router.push('/profile')
}

// 菜单选择处理
const handleSelect = (key) => {
  switch (key) {
    case '1':
      router.push('/')
      break
    case '2':
      router.push('/house/search')
      break
    case '3':
      router.push('/house/publish')
      break
    case '4':
      router.push('/message')
      break
  }
}

// 查看房源详情
const viewHouseDetail = (id) => {
  router.push(`/rental/agent/house-detail/${id}`)
}

// 处理房源操作
const handleHouseAction = (house) => {
  switch (house.status) {
    case '推广中':
      stopPromotion(house)
      break
    case '申请取消中':
      viewCancelProgress(house)
      break
    case '已完成':
      ElMessage.info('房源已完成代理')
      break
    default:
      ElMessage.info('管理房源')
  }
}

// 停止推广 - 提交取消申请
const stopPromotion = (house) => {
  ElMessageBox.prompt(
      `申请停止"${house.title}"的推广需要房东同意，请输入申请原因：`,
      '申请停止推广',
      {
        confirmButtonText: '提交申请',
        cancelButtonText: '取消',
        inputPattern: /\S/,
        inputErrorMessage: '申请原因不能为空',
        inputPlaceholder: '请输入申请停止推广的原因'
      }
  ).then(({ value }) => {
    // 更新房源状态为申请取消中
    house.status = '申请取消中'
    house.statusClass = 'cancelling'
    house.cancelRequest = {
      id: `CR${Date.now()}`,
      applyTime: new Date().toLocaleString(),
      reason: value,
      status: 'pending'
    }
    ElMessage.success('取消申请已提交，等待房东审核')
  }).catch(() => {
    // 用户取消操作
  })
}

// 查看取消申请进度
const cancelProgressVisible = ref(false)
const currentCancelRequest = ref(null)

const viewCancelProgress = (house) => {
  currentCancelRequest.value = house.cancelRequest
  cancelProgressVisible.value = true
}

const getProgressStatus = (status) => {
  switch (status) {
    case 'pending':
      return '待审核'
    case 'approved':
      return '已同意'
    case 'rejected':
      return '已拒绝'
    default:
      return '未知状态'
  }
}

const getProgressType = (status) => {
  switch (status) {
    case 'pending':
      return 'warning'
    case 'approved':
      return 'success'
    case 'rejected':
      return 'danger'
    default:
      return 'info'
  }
}

// 快捷操作跳转
const goToAppointments = () => {
  router.push('/agent/appointments')
}

const goToReports = () => {
  ElMessage.info('业绩报告功能开发中')
}

// 推广中房源
const promotingHousesList = computed(() => {
  return allHousesData.value.filter(house => house.status === '推广中')
})

// 已完成房源
const completedHousesList = computed(() => {
  return allHousesData.value.filter(house => house.status === '已完成')
})

// 所有房源
const allHouses = computed(() => {
  return allHousesData.value
})

// 处理标签页切换
const handleTabChange = (tab) => {
  activeTab.value = tab
  ElMessage.info(`切换到${tab === 'all' ? '所有代理' : tab === 'promoting' ? '推广中' : '已完成'}标签页`)
}

// 分页相关方法
const handleSizeChange = (val) => {
  pageSize.value = val
  ElMessage.info(`每页显示 ${val} 条`)
}

const handleCurrentChange = (val) => {
  currentPage.value = val
  ElMessage.info(`当前页: ${val}`)
}

// 获取中介代理的所有房源
const fetchAgentHouses = async () => {
  try {
    loading.value = true
    const response = await api.get('/agent-rental/getAllAgentHouse', {
      headers: {
        'info': getToken()
      }
    })

    if (response.data.code === 200) {
      allHousesData.value = response.data.data.map(house => ({
        id: house.houseId,
        title: house.houseSummary,
        address: house.houseLocation,
        price: house.rent,
        layout: getLayoutText(house.layout),
        area: house.area,
        orientation: house.orientation,
        image: house.houseImages?.[0] || 'https://images.unsplash.com/photo-1560448204-e02f11c3d0e2',
        tags: getHouseTags(house),
        status: getHouseStatus(house.rentStatus),
        statusClass: getStatusClass(house.rentStatus)
      }))

      // 更新统计数据
      updateStats()
    }
  } catch (error) {
    console.error('获取房源数据失败:', error)
    ElMessage.error('获取房源数据失败，请稍后重试')
  } finally {
    loading.value = false
  }
}

// 获取户型文本
const getLayoutText = (layout) => {
  const layoutMap = {
    1: '一居室',
    2: '两居室',
    3: '三居室',
    4: '四居室',
    5: '五居室'
  }
  return layoutMap[layout] || '未知户型'
}

// 获取房源标签
const getHouseTags = (house) => {
  const tags = []
  if (house.subwayInfo) tags.push('近地铁')
  if (house.complementaryFacilities?.hasAirConditioner) tags.push('空调')
  if (house.complementaryFacilities?.hasWifi) tags.push('WiFi')
  if (house.complementaryFacilities?.hasWashingMachine) tags.push('洗衣机')
  return tags
}

// 获取房源状态
const getHouseStatus = (rentStatus) => {
  const statusMap = {
    0: '推广中',
    1: '已出租',
    2: '已下架'
  }
  return statusMap[rentStatus] || '未知状态'
}

// 获取状态样式类
const getStatusClass = (rentStatus) => {
  const classMap = {
    0: 'promoting',
    1: 'completed',
    2: 'cancelled'
  }
  return classMap[rentStatus] || 'promoting'
}

// 更新统计数据
const updateStats = () => {
  totalHouses.value = allHousesData.value.length
  promotingHouses.value = allHousesData.value.filter(h => h.status === '推广中').length
  completedHouses.value = allHousesData.value.filter(h => h.status === '已出租').length
  tenantsCount.value = completedHouses.value // 简化处理，实际应该从后端获取
}

// 跳转到申请页面
const goToApply = () => {
  router.push('/rental/agent/apply')
}

// 页面加载时获取数据
onMounted(() => {
  // 首先检查用户角色
  if (!canAccessAgentFeatures()) {
    const userInfo = getUserInfo()
    if (userInfo?.role === 1) {
      ElMessage.error('您还不是中介，请先申请成为中介')
    } else if (userInfo?.role === 2) {
      ElMessage.error('房东用户不能访问中介功能')
    } else {
      ElMessage.error('用户角色不符合访问条件')
    }
    router.push('/')
    return
  }

  checkAgentStatus()
  fetchAgentHouses()
})
</script>

<style scoped>
.agent-rental-container {
  display: flex;
  min-height: 100vh;
  overflow: hidden;
  position: relative;
  background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
}

.background-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 0;
}

/* 精美的动态背景 */
.dynamic-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(to bottom, #1a2980, #26d0ce);
  overflow: hidden;
}

/* 建筑物 */
.building {
  position: absolute;
  bottom: 0;
  background: rgba(30, 30, 50, 0.8);
  border-radius: 5px 5px 0 0;
  box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.3);
}

.building-1 {
  left: 10%;
  width: 80px;
  height: 300px;
  animation: buildingGlow 4s infinite alternate;
}

.building-2 {
  left: 25%;
  width: 120px;
  height: 400px;
  animation: buildingGlow 5s infinite alternate-reverse;
}

.building-3 {
  left: 45%;
  width: 100px;
  height: 350px;
  animation: buildingGlow 6s infinite alternate;
}

.building-4 {
  left: 65%;
  width: 140px;
  height: 450px;
  animation: buildingGlow 4.5s infinite alternate-reverse;
}

.building-5 {
  left: 80%;
  width: 90px;
  height: 320px;
  animation: buildingGlow 5.5s infinite alternate;
}

@keyframes buildingGlow {
  0% {
    box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.3);
  }
  100% {
    box-shadow: 0 -5px 25px rgba(100, 200, 255, 0.6);
  }
}

/* 云朵 */
.cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  filter: blur(2px);
}

.cloud-1 {
  top: 20%;
  left: 5%;
  width: 80px;
  height: 30px;
  animation: cloudMove 25s linear infinite;
}

.cloud-2 {
  top: 35%;
  left: 70%;
  width: 120px;
  height: 40px;
  animation: cloudMove 30s linear infinite;
}

.cloud-3 {
  top: 15%;
  left: 40%;
  width: 100px;
  height: 35px;
  animation: cloudMove 35s linear infinite;
}

@keyframes cloudMove {
  0% {
    transform: translateX(-100px);
  }
  100% {
    transform: translateX(calc(100vw + 100px));
  }
}

/* 太阳 */
.sun {
  position: absolute;
  top: 80px;
  right: 100px;
  width: 80px;
  height: 80px;
  background: radial-gradient(circle, #ffeb3b, #ffc107);
  border-radius: 50%;
  box-shadow: 0 0 40px #ff9800, 0 0 80px #ff5722;
  animation: sunPulse 3s infinite alternate;
}

@keyframes sunPulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 40px #ff9800, 0 0 80px #ff5722;
  }
  100% {
    transform: scale(1.1);
    box-shadow: 0 0 60px #ff9800, 0 0 100px #ff5722;
  }
}

/* 光线 */
.light-ray {
  position: absolute;
  top: 120px;
  right: 140px;
  width: 400px;
  height: 200px;
  background: linear-gradient(to right, transparent, rgba(255, 235, 59, 0.2), transparent);
  transform-origin: left center;
  animation: rayRotate 10s infinite linear;
}

.ray-1 {
  transform: rotate(0deg);
  animation-delay: 0s;
}

.ray-2 {
  transform: rotate(60deg);
  animation-delay: 2s;
}

.ray-3 {
  transform: rotate(120deg);
  animation-delay: 4s;
}

@keyframes rayRotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* 浮动装饰元素 */
.floating-shape {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  animation: float 15s infinite linear;
}

.shape-1 {
  width: 300px;
  height: 300px;
  top: -100px;
  left: -100px;
  animation-duration: 20s;
  background: radial-gradient(circle, rgba(74, 144, 226, 0.2) 0%, transparent 70%);
}

.shape-2 {
  width: 200px;
  height: 200px;
  bottom: -80px;
  right: -80px;
  animation-duration: 25s;
  animation-direction: reverse;
  background: radial-gradient(circle, rgba(255, 107, 107, 0.2) 0%, transparent 70%);
}

.shape-3 {
  width: 150px;
  height: 150px;
  top: 30%;
  right: 20%;
  animation-duration: 15s;
  background: radial-gradient(circle, rgba(80, 227, 194, 0.2) 0%, transparent 70%);
}

.shape-4 {
  width: 100px;
  height: 100px;
  bottom: 20%;
  left: 20%;
  animation-duration: 18s;
  animation-direction: reverse;
  background: radial-gradient(circle, rgba(255, 209, 102, 0.2) 0%, transparent 70%);
}

.shape-5 {
  width: 250px;
  height: 250px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-duration: 22s;
  background: radial-gradient(circle, rgba(155, 89, 182, 0.2) 0%, transparent 70%);
}

.shape-6 {
  width: 180px;
  height: 180px;
  top: 70%;
  left: 10%;
  animation-duration: 28s;
  background: radial-gradient(circle, rgba(231, 76, 60, 0.2) 0%, transparent 70%);
}

@keyframes float {
  0% {
    transform: translate(0, 0) rotate(0deg);
  }
  25% {
    transform: translate(20px, 20px) rotate(90deg);
  }
  50% {
    transform: translate(0, 40px) rotate(180deg);
  }
  75% {
    transform: translate(-20px, 20px) rotate(270deg);
  }
  100% {
    transform: translate(0, 0) rotate(360deg);
  }
}

.agent-rental-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  z-index: 1;
  position: relative;
}

.top-navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 30px;
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.app-title {
  color: white;
  font-size: 24px;
  font-weight: 700;
  margin: 0;
}

.navbar-center {
  flex: 1;
  margin: 0 20px;
}

:deep(.el-menu--horizontal) {
  border: none;
  background: transparent !important;
}

:deep(.el-menu--horizontal .el-menu-item) {
  color: white;
  border: none;
}

:deep(.el-menu--horizontal .el-menu-item:hover) {
  background: rgba(255, 255, 255, 0.2) !important;
}

:deep(.el-menu--horizontal .el-menu-item.is-active) {
  color: #4A90E2 !important;
  border: none;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: white;
}

.username {
  font-size: 16px;
  font-weight: 500;
}

.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.sidebar {
  width: 250px;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  padding: 20px 0;
  height: 100%;
  box-shadow: 3px 0 10px rgba(0, 0, 0, 0.2);
}

.el-menu-vertical {
  border: none !important;
  height: 100%;
}

.el-menu-item,
.el-sub-menu__title {
  margin: 5px 10px;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.el-menu-item:hover,
.el-sub-menu__title:hover {
  background-color: rgba(255, 255, 255, 0.1) !important;
}

.agent-rental-content {
  height: 100%;
  overflow-y: auto;
  padding: 20px;
}

.agent-rental-content::-webkit-scrollbar {
  width: 8px;
}

.agent-rental-content::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.agent-rental-content::-webkit-scrollbar-thumb {
  background: rgba(74, 144, 226, 0.6);
  border-radius: 4px;
}

.agent-rental-content::-webkit-scrollbar-thumb:hover {
  background: rgba(74, 144, 226, 0.8);
}

.rental-header {
  margin-bottom: 30px;
}

.rental-header h2 {
  color: #2c3e50;
  font-size: 28px;
  margin: 0 0 10px;
}

.rental-header p {
  color: #7f8c8d;
}

.rental-stats {
  margin-bottom: 30px;
}

.stat-card {
  display: flex;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.stat-icon {
  width: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: white;
}

.stat-content {
  flex: 1;
  padding: 15px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: #2c3e50;
  margin-bottom: 5px;
}

.stat-title {
  font-size: 14px;
  color: #7f8c8d;
}

.bg-blue {
  background: linear-gradient(135deg, #4A90E2 0%, #6b93d8 100%);
}

.bg-green {
  background: linear-gradient(135deg, #7ED321 0%, #8bc34a 100%);
}

.bg-orange {
  background: linear-gradient(135deg, #FFA500 0%, #ffb74d 100%);
}

.bg-red {
  background: linear-gradient(135deg, #FF6B6B 0%, #ff8a80 100%);
}

.bg-purple {
  background: linear-gradient(135deg, #9B59B6 0%, #ba68c8 100%);
}

/* 快捷操作样式 */
.quick-actions {
  margin-bottom: 30px;
}

.action-card {
  display: flex;
  align-items: center;
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: all 0.3s ease;
}

.action-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
}

.action-icon {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4A90E2 0%, #6b93d8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
  margin-right: 15px;
}

.action-content {
  flex: 1;
}

.action-title {
  font-size: 16px;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 5px;
}

.action-desc {
  font-size: 14px;
  color: #7f8c8d;
}

.rental-container {
  padding: 20px 0;
}

.house-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: all 0.3s ease;
  height: 100%;
}

.house-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
}

.house-image {
  position: relative;
  height: 200px;
}

.house-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.house-card:hover .house-image img {
  transform: scale(1.05);
}

.house-price {
  position: absolute;
  top: 15px;
  right: 15px;
  background: rgba(74, 144, 226, 0.9);
  color: white;
  padding: 5px 10px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 14px;
}

.house-status {
  position: absolute;
  top: 15px;
  left: 15px;
  padding: 5px 10px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 12px;
  color: white;
}

.house-status.promoting {
  background: #50E3C2;
}

.house-status.cancelling {
  background: #FF9500;
}

.house-status.completed {
  background: #9B9B9B;
}

.house-info {
  padding: 20px;
}

.house-title {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 700;
  color: #2c3e50;
}

.house-address {
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 0 0 15px;
  font-size: 14px;
  color: #7f8c8d;
}

.house-meta {
  display: flex;
  gap: 15px;
  margin-bottom: 15px;
  font-size: 13px;
  color: #7f8c8d;
}

.house-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.house-actions {
  display: flex;
  gap: 10px;
}

.pagination-container {
  display: flex;
  justify-content: center;
  padding: 20px 0;
}

@media (max-width: 992px) {
  .sidebar {
    width: 80px;
  }

  .app-title,
  .el-menu-item span,
  .el-sub-menu__title span {
    display: none;
  }

  .rental-stats .el-row {
    flex-direction: column;
    gap: 15px;
  }

  .rental-stats .el-col {
    width: 100%;
  }

  .rental-container .el-row {
    flex-direction: column;
    gap: 15px;
  }

  .rental-container .el-col {
    width: 100%;
  }

  .no-access-card {
    padding: 40px 20px;
  }

  .no-access-actions {
    flex-direction: column;
    align-items: center;
  }

  .no-access-actions .el-button {
    width: 200px;
  }
}

/* 无权限访问样式 */
.no-access-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 60vh;
  padding: 40px 20px;
}

.no-access-card {
  background: white;
  border-radius: 20px;
  padding: 60px 40px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
  max-width: 600px;
  width: 100%;
}

.no-access-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 30px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  color: white;
}

.no-access-card h2 {
  color: #2c3e50;
  font-size: 28px;
  margin: 0 0 15px;
  font-weight: 700;
}

.no-access-card p {
  color: #7f8c8d;
  font-size: 16px;
  margin: 0 0 30px;
  line-height: 1.6;
}

.no-access-actions {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-bottom: 40px;
  flex-wrap: wrap;
}

.no-access-tips {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 25px;
  text-align: left;
}

.no-access-tips h3 {
  color: #2c3e50;
  font-size: 18px;
  margin: 0 0 15px;
  font-weight: 600;
}

.no-access-tips ol {
  margin: 0;
  padding-left: 20px;
  color: #5a6c7d;
}

.no-access-tips li {
  margin-bottom: 8px;
  line-height: 1.5;
}
</style>
